# -*- coding: utf-8 -*-

'''
@author: Luis Fonte n6043
@date: 10/06/2013
@obs: Code created on class from documentation given by teacher
'''


class Insertion():
    '''
    Class Insertion
    Class with a insertion sort algorithm implemented on function insertionSort
    '''

    
    def __init__(self, A):
        '''
        Class Constructor
        @param A - list with numbers disordered
        '''
        self.A = A #list passed by parameter
        pass
    

    
    def insertionSort(self):
        '''
        insertionSort function
        Builds a final sorted list one item at a time
        '''
        for j in xrange(1, len(self.A)):
            key = self.A[j] #key is the value j from A
            i = j-1
            while i > -1 and self.A[i] > key: # while the key values are inferior to A values
                self.A[i+1] = self.A[i] #and does the insertion
                i = i-1
            self.A[i+1] = key
        
        pass

    
